// 导航标题
fetch('http://chst.vip:1234/api/getbaicaijiatitle')
    .then(body => body.json())
    .then(res => {
        console.log(res.result)

        let el = '';
        res.result.forEach(item => {
            el += `<li titleid="${item.titleId}">${item.title}</li>`
        })
        $('.nav_lis').html(el)
    })

// 详情列表
fetch('http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0')
    .then(body => body.json())
    .then(res => {
        console.log(res.result)

        let str = ''
        res.result.forEach(item => {
            str += `<li>
        ${item.productImg}
        <div class="main-right">
           <div class="top">
             <h4>${item.productName}</h4>
             <p>
               ${item.productPrice}
               <del>1888.0</del>
              </p>
           </div>
           <div class="bottom">
             <div>
             <div class="scorll">${item.productCouponRemain}</div>
               <p>点此领取优惠券</p>
               ${item.productHref}
              </div>
           </div>
        </div>
      </li>`
        })
        $('.main').html(str)
    
        setInterval(function(){
            $('.bar').find(i).css('width')
        },100)
        
    })


$('.nav_lis').on('click', 'li', function () {
    console.log($(this))
    $('.main').stop().html('').finish()
    let titleid = $(this).attr('titleid')
    $(this).css('color', '#fc353a').siblings().css('color', '#000')
    console.log(titleid);

    fetch(`http://chst.vip:1234/api/getbaicaijiaproduct?titleid=${titleid}`)
        .then(body => body.json())
        .then(res => {
            let ss = '';
            res.result.forEach(item => {
                ss += `<li>
                            ${item.productImg}
                            <div class="main-right">
                                <div class="top">
                                <h4>${item.productName}</h4>
                                <p>
                                    ${item.productPrice}
                                    <del>1888.0</del>
                                    </p>
                                </div>
                                <div class="bottom">
                                <div>
                                <div class="scorll"></div>
                                    ${item.productCouponRemain}
                                    <p>点此领取优惠券</p>
                                    ${item.productHref}
                                    </div>
                                </div>
                            </div>
                            </li>`
            })
            $('.main').html(ss)
        })

})


// 返回顶部
let toTop = $('.gotop').get(0)
// console.log(toTop)

toTop.onclick = function (e) {
//   console.log(123)
  document.documentElement.scrollTop = 0;
}